package pl.koziczak.knowledgeintegration.utils;

import java.io.File;
import java.io.IOException;

import pl.koziczak.knowledgeintegration.exception.KnowledgeIntegrationException;

public class FileUtils {
	
	public static File parsePath(String xmlFilePath, boolean create, boolean addTimeStamp) throws KnowledgeIntegrationException {
		File file = new File(xmlFilePath);
		
		if(!file.exists()) {
			if(create) {
				try {
					if(addTimeStamp) {
						xmlFilePath = xmlFilePath.replaceFirst(".xml", "_"+System.currentTimeMillis()+".xml");
						file = new File(xmlFilePath);
					}
					file.createNewFile();
				} catch (IOException e) {
					throw new KnowledgeIntegrationException(e);
				}
			} else
				throw new KnowledgeIntegrationException("CAN NOT FIND FILE: " + xmlFilePath);
		}
		return file;
	}
	
}
